﻿@model List<BenzInfo.Hockey.Grenadiers.Models.Post>

@{
    ViewBag.Title = BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Contest;
}

<script type="text/javascript">

    $(document).ready(function () {
        $('#dialog_contest').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });
        $('#btn_add a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddContest';

            $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');

            $('#dialog_contest').empty().load(url, function () {
                $('#dialog_contest').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_edit a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';

            $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');

            $('#dialog_contest').empty().load(url, function () {
                $('#dialog_contest').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
    });

</script>

<h1>@(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Contest)</h1>

<div id="dialog_contest"></div>

@if (ViewBag.CurrentUser != null)
{
    <span id="btn_add">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddContest, "Add", "Contest")</span>
}

<div id="news">
     @for (int index = 0; index < Model.Count(); index++)
     {   
        <div> 
            @if (Model[index].Picture != null)
            {   
                    <img alt="" src="@Url.Content("~/Utils/ImageHandler.ashx?src=posts/" + Model[index].Picture + "&maxwidth=250&maxheight=500")" title="@(ViewBag.Lang == "fr" ? Model[index].TitleFR : Model[index].TitleEN)" />
            }
            @Html.Raw(ViewBag.Lang == "fr" ? Model[index].ContentFR.ToString().Replace("\n", "<br />") : Model[index].ContentEN.ToString().Replace("\n", "<br />"))
            @if (ViewBag.CurrentUser != null)
            {         
                <div><span id="btn_edit">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit, "Edit", new { id = @Model[index].Id })</span>
                @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete, "Delete", new { id = @Model[index].Id }, new { onclick = "return confirm('Delete?')" })</div>  
            }
        </div>
         <div class="clear"></div>
     }
    
</div>
